package spark.core.scala

import org.apache.spark.{SparkContext, SparkConf}

/**
 * come from zhonghuashishan
 */
object WordCount {

  def main(args: Array[String]) {
    val conf = new SparkConf()
    .setAppName("WordCount")

    val sc = new SparkContext(conf)
    val lines = sc.textFile("hdfs://bigdata00:8020/wordcount.txt")
    val words = lines.flatMap(line => line.split(" "))
    val pairs = words.map(word => (word,1))
    val wordCounts = pairs.reduceByKey(_+_)

    wordCounts.foreach(wordcount => println(wordcount._1+" appeared "+wordcount._2 +" times."))
  }
}
